<template>
	<uni-popup ref="popup" type="bottom" class="popup">
		<view class="popup-content">
			<view class="picker-header">
				<view @click="onClose">取消</view>
				<view v-if="title" class="packer-title">{{ title }}</view>
				<view @click="onConfirm">确定</view>
			</view>
			<picker-view :value="value" @change="onChange" class="picker">
				<picker-view-column>
					<view class="picker-row" v-for="item in options" :key="item.value">
						{{ item.name }}
					</view>
				</picker-view-column>
			</picker-view>
		</view>
	</uni-popup>
</template>

<script>
	import {
		getChemicalList
	} from '@/api/load-operation/add-load-operation.js';
	import {
		mapGetters
	} from 'vuex';
	import dayjs from 'dayjs';
	export default {
		props: {
			title: String,
		},
		data() {
			return {
				options: [],
				value: [0],
			};
		},
		methods: {
			// 打开
			open() {
				this.$refs.popup.open();
			},
			//确定
			onConfirm() {
				let selectData = {};
				if (Array.isArray(this.value) && this.value.length) {
					selectData = {
						value: this.options[this.value[0]]?.value,
						name: this.options[this.value[0]]?.name,
						formTypeLabel: this.options[this.value[0]]?.formTypeLabel,
						formTypes: this.options[this.value[0]]?.formTypes
					};
				}

				this.$emit('confirm', selectData);
				this.onClose();
			},
			// 取消
			onClose() {
				this.$refs.popup.close();
			},
			//滑动picker
			onChange(e) {
				this.value = e.detail.value;
			},
			async query() {
				const {
					data
				} = await getChemicalList();
				this.options = data.map((item) => ({
					name: item.chemicalName,
					value: item.formId,
					formTypeLabel: item.formTypeLabel,
					formTypes: item.formTypes
				}));
			},
		},
		computed: {
			...mapGetters(['deptId', 'staffId']),
		},
		created() {
			this.query();
		},
	};
</script>

<style lang="scss" scoped>
	::v-deep .bottom {
		margin-bottom: 0 !important;
	}

	.popup-content {
		background: #fff;
	}

	.picker-header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin: 0 20rpx;
		padding: 20rpx 0;
	}

	.picker {
		height: 490rpx;
	}

	.picker-row {
		text-align: center;
		line-height: 70rpx;
		text-overflow: ellipsis;
	}
</style>